<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="甲方识别码" prop="nbajbh">
        <el-input
          v-model="queryParams.nbajbh"
          placeholder="请输入甲方识别码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件名称" prop="ajmc">
        <el-input
          v-model="queryParams.ajmc"
          placeholder="请输入案件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="zt">
        <el-select v-model="queryParams.zt" placeholder="请选择状态" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.fs_task_zt"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fs:push:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pushList" @selection-change="handleSelectionChange">
      <el-table-column label="甲方识别码" align="center" prop="nbajbh"/>
      <el-table-column label="案件名称" align="center" prop="ajmc"/>
      <el-table-column label="重提要求" align="center" prop="ctyq" width="200px" :show-overflow-tooltip="toolTip"/>
      <el-table-column label="状态" align="center" prop="zt">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fs_task_zt" :value="scope.row.zt"/>
        </template>
      </el-table-column>
      <el-table-column label="创建" align="center" prop="cjrMc">
        <template slot-scope="scope">
          <span>{{ scope.row.cjrMc }}</span>
          <br>
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成" align="center" prop="cjrMc">
        <template slot-scope="scope"  v-if="scope.row.zt==3">
          <span>{{ scope.row.ssrMc }}</span>
          <br>
          <span>{{ parseTime(scope.row.wcsj, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.zt==1"
            size="mini"
            type="text"
            icon="el-icon-caret-right"
            @click="handleStart(scope.row)"
            v-hasPermi="['fs:post:edit']"
          >开始
          </el-button>
          <el-button v-if="scope.row.zt==2"
            size="mini"
            type="text"
            icon="el-icon-finished"
            @click="handleComplete(scope.row)"
            v-hasPermi="['fs:post:edit']"
          >完成
          </el-button>
          <el-button v-if="scope.row.zt==1"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fs:post:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改重提工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="关联案件id" prop="caseId">
          <el-input v-model="form.caseId" placeholder="请输入关联案件id"/>
        </el-form-item>
        <el-form-item label="关联内部案件编号" prop="nbajbh">
          <el-input v-model="form.nbajbh" placeholder="请输入关联内部案件编号"/>
        </el-form-item>
        <el-form-item label="案件名称" prop="ajmc">
          <el-input v-model="form.ajmc" placeholder="请输入案件名称"/>
        </el-form-item>
        <el-form-item label="重提要求" prop="ctyq">
          <el-input v-model="form.ctyq" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="状态" prop="zt">
          <el-select v-model="form.zt" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.fs_task_zt"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建人id" prop="cjr">
          <el-input v-model="form.cjr" placeholder="请输入创建人id"/>
        </el-form-item>
        <el-form-item label="所属人id" prop="ssr">
          <el-input v-model="form.ssr" placeholder="请输入所属人id"/>
        </el-form-item>
        <el-form-item label="分配时间" prop="fpsj">
          <el-date-picker clearable
                          v-model="form.fpsj"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择分配时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="完成时间" prop="wcsj">
          <el-date-picker clearable
                          v-model="form.wcsj"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择完成时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import {listPush, getPush, delPush, addPush, updatePush, start, complete} from "@/api/fs/push";

export default {
  name: "Push",
  dicts: ['fs_task_zt'],
  data() {
    return {
      // 遮罩层
      loading: true,
      toolTip: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 重提工单表格数据
      pushList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        caseId: null,
        nbajbh: null,
        ajmc: null,
        ctyq: null,
        zt: 1,
        cjr: null,
        ssr: null,
        fpsj: null,
        wcsj: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.queryParams.zt = 1;
    this.getList();
  },
  methods: {
    /** 查询重提工单列表 */
    getList() {
      this.loading = true;
      listPush(this.queryParams).then(response => {
        this.pushList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        caseId: null,
        nbajbh: null,
        ajmc: null,
        ctyq: null,
        zt: null,
        cjr: null,
        cjrMc: null,
        ssr: null,
        ssrMc: null,
        fpsj: null,
        wcsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加重提工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPush(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改重提工单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePush(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPush(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除重提工单编号为"' + ids + '"的数据项？').then(function () {
        return delPush(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fs/push/export', {
        ...this.queryParams
      }, `push_${new Date().getTime()}.xlsx`)
    },
    handleStart(row) {
      this.reset();
      const id = row.id;
      start(id).then(response => {
        this.$modal.msgSuccess("已开始，请尽快完成");
        this.getList();
      });
    },
    handleComplete(row) {
      this.reset();
      const id = row.id;
      complete(id).then(response => {
        this.$modal.msgSuccess("已完成该工单！");
        this.getList();
      });
    },
  }
};
</script>
